import cinemaJs from '../controllers/cinema'
import profileJs from '../controllers/profile'
import movieJs  from  '../controllers/moviecontrollers'
import indexJs from '../controllers/movie-index'
import detialJs from '../controllers/detial'
import willJs  from '../controllers/will'
class router{
constructor(){
    this.render()
}

renderDom(hash){
let obj={
 cinemaJs,
 movieJs,
 profileJs,
 detialJs,
 willJs
}
indexJs.render()

obj[hash].render()
}

setActiveClass(hash){
$(`footer li[data-index=${hash}`).addClass('active').siblings().removeClass('active')
$(`.nav-box div[data-to=${hash}`).addClass('tap').siblings().removeClass('tap')
}

    render(){
   window.addEventListener('load',this.handlePageload.bind(this))
   window.addEventListener('hashchange',this.handleHashchange.bind(this))  
    }

    handlePageload(){
        let hash=location.hash.substr(1) || 'movieJs'
      //  indexJs.render()
        location.hash=hash
        let re=/\w+Js/g
        let hash2=hash.match(re)
        this.renderDom(hash2)
        this.setActiveClass(hash2)
    }
    handleHashchange(){
 let hash=location.hash.substr(1)
 let re=/\w+Js/g
 let hash2=hash.match(re)
 this.renderDom(hash2)
 this.setActiveClass(hash2)
    }

}

new router()